<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* Mapv (https://github.com/huiyan-fe/mapv)
*********************************************************************-->
<!DOCTYPE html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <script type="text/javascript" include="mapv" src="../../dist/ol/include-ol.js"></script>
    <title data-i18n="resources.title_mapvQianxi"></title>
    <style>
        .ol-popup {
            position: absolute;
            background-color: white;
            -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
            filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
            padding: 15px;
            border-radius: 10px;
            border: 1px solid #cccccc;
            bottom: 12px;
            left: -50px;
            min-width: 280px;
            font-size: 8pt;
        }

        .ol-popup:after, .ol-popup:before {
            top: 100%;
            border: solid transparent;
            content: " ";
            height: 0;
            width: 0;
            position: absolute;
            pointer-events: none;
        }

        .ol-popup:after {
            border-top-color: white;
            border-width: 10px;
            left: 48px;
            margin-left: -10px;
        }

        .ol-popup:before {
            border-top-color: #cccccc;
            border-width: 11px;
            left: 48px;
            margin-left: -11px;
        }

        .ol-popup-closer {
            text-decoration: none;
            position: absolute;
            top: 2px;
            right: 8px;
        }

        .ol-popup-closer:after {
            content: "✖";
        }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="map" style="width: 100%;height:100%"></div>
<div id="popup" class="ol-popup">
    <a href="#" id="popup-closer" class="ol-popup-closer"></a>
    <div id="popup-content" data-i18n="resources.text_iClient"></div>
</div>
<script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
<script type="text/javascript">
    var container = document.getElementById('popup');
    var closer = document.getElementById('popup-closer');
    var overlay = new ol.Overlay(({
        element: container,
        autoPan: true,
        autoPanAnimation: {
            duration: 250
        }
    }));
    closer.onclick = function () {
        overlay.setPosition(undefined);
        closer.blur();
        return false;
    };

    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var url = host + "/iserver/services/map-china/rest/maps/ChinaDark";
    var map = new ol.Map({
        target: 'map',
        // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
        controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
            .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
        view: new ol.View({
            center: [113.2, 37.82],
            zoom: 5,
            projection: 'EPSG:4326'
        }),
        layers: [new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest({
                url: url,
                prjCoordSys: {"epsgCode": 4326},
                attributions: "Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a>"
            }),
            projection: 'EPSG:4326'
        })]
    });

    overlay.setPosition(map.getView().getCenter());

    $.get('../data/china.json', function (geojson) {

        var geojsonOptions = {
            gradient: {
                0: 'rgba(55, 50, 250, 0.4)',
                1: 'rgba(55, 50, 250, 1)'
            },
            max: 354551,
            draw: 'intensity'
        };

        var geojsonDataSet = mapv.geojson.getDataSet(geojson);

        var to = '北京';

        var qianxi = new mapv.DataSet([
            {
                from: '河北',
                count: 354551,
                to: to,
            },
            {
                from: '天津',
                count: 97323,
                to: to,
            },
            {
                from: '山东',
                count: 28664,
                to: to,
            },
            {
                from: '山西',
                count: 16650,
                to: to,
            },
            {
                from: '辽宁',
                count: 14379,
                to: to,
            },
            {
                from: '河南',
                count: 10980,
                to: to,
            },
            {
                from: '内蒙古自治区',
                count: 9603,
                to: to,
            },
            {
                from: '江苏',
                count: 4536,
                to: to,
            },
            {
                from: '上海',
                count: 3556,
                to: to,
            },
            {
                from: '广东',
                count: 2600,
                to: to,
            },
        ]);

        var qianxiData = qianxi.get();

        var lineData = [];
        var pointData = [];
        var textData = [];
        var timeData = [];

        var citys = {};

        for (var i = 0; i < qianxiData.length; i++) {
            var fromCenter = mapv.utilCityCenter.getCenterByCityName(qianxiData[i].from);
            var toCenter = mapv.utilCityCenter.getCenterByCityName(qianxiData[i].to);
            if (!fromCenter || !toCenter) {
                continue;
            }
            citys[qianxiData[i].from] = qianxiData[i].count;
            citys[qianxiData[i].to] = 100;
            pointData.push(
                {
                    geometry: {
                        type: 'Point',
                        coordinates: [fromCenter.lng, fromCenter.lat]
                    }
                }
            );
            pointData.push(
                {
                    geometry: {
                        type: 'Point',
                        coordinates: [toCenter.lng, toCenter.lat]
                    }
                }
            );
            textData.push(
                {
                    geometry: {
                        type: 'Point',
                        coordinates: [fromCenter.lng, fromCenter.lat]
                    },
                    text: qianxiData[i].from
                }
            );
            textData.push(
                {
                    geometry: {
                        type: 'Point',
                        coordinates: [toCenter.lng, toCenter.lat]
                    },
                    text: qianxiData[i].to
                }
            );

            var curve = mapv.utilCurve.getPoints([fromCenter, toCenter]);

            for (j = 0; j < curve.length; j++) {
                timeData.push({
                    geometry: {
                        type: 'Point',
                        coordinates: curve[j]
                    },
                    count: 1,
                    time: j
                });
            }

            lineData.push({
                geometry: {
                    type: 'LineString',
                    coordinates: curve
                    //coordinates: [[fromCenter.lng, fromCenter.lat], [toCenter.lng, toCenter.lat]]
                },
                count: 30 * Math.random()
            });

        }

        var data = geojsonDataSet.get({
            filter: function (item) {

                if (!citys[item.name]) {
                    return false;
                }

                item.count = citys[item.name];
                return true;
            }
        });
        geojsonDataSet = new mapv.DataSet(data);
        map.addLayer(new ol.layer.Image({
            source: new ol.source.Mapv({map: map, dataSet: geojsonDataSet, mapvOptions: geojsonOptions})
        }));

        var textDataSet = new mapv.DataSet(textData);

        var textOptions = {
            draw: 'text',
            font: '14px Arial',
            fillStyle: 'white',
            shadowColor: 'yellow',
            shadowBlue: 10,
            zIndex: 11,
            shadowBlur: 10
        };
        map.addLayer(new ol.layer.Image({
            source: new ol.source.Mapv({map: map, dataSet: textDataSet, mapvOptions: textOptions})
        }));

        var lineDataSet = new mapv.DataSet(lineData);

        var lineOptions = {
            strokeStyle: 'rgba(255, 250, 50, 0.8)',
            shadowColor: 'rgba(255, 250, 50, 1)',
            shadowBlur: 20,
            lineWidth: 2,
            zIndex: 100,
            draw: 'simple'
        };

        map.addLayer(new ol.layer.Image({
            source: new ol.source.Mapv({map: map, dataSet: lineDataSet, mapvOptions: lineOptions})
        }));

        var pointOptions = {
            fillStyle: 'rgba(254,175,3,0.7)',
            shadowColor: 'rgba(55, 50, 250, 0.5)',
            shadowBlur: 10,
            size: 5,
            zIndex: 10,
            draw: 'simple'
        };


        var pointDataSet = new mapv.DataSet(pointData);

        map.addLayer(new ol.layer.Image({
            source: new ol.source.Mapv({map: map, dataSet: pointDataSet, mapvOptions: pointOptions})
        }));

        var timeDataSet = new mapv.DataSet(timeData);

        var timeOptions = {
            fillStyle: 'rgba(255, 250, 250, 0.5)',
            zIndex: 200,
            size: 2.5,
            animation: {
                type: 'time',
                stepsRange: {
                    start: 0,
                    end: 50
                },
                trails: 10,
                duration: 2,
            },
            draw: 'simple'
        };
        map.addLayer(new ol.layer.Image({
            source: new ol.source.Mapv({map: map, dataSet: timeDataSet, mapvOptions: timeOptions})
        }));

    });

</script>
</body>
</html>
